package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 扫描仪连接类型枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum ScannerConnectionType implements BaseEnum {
    USB("USB", "USB连接"),
    NETWORK("NETWORK", "网络连接"),
    WIRELESS("WIRELESS", "无线连接"),
    BLUETOOTH("BLUETOOTH", "蓝牙连接"),
    SERIAL("SERIAL", "串口连接"),
    PARALLEL("PARALLEL", "并口连接");

    private final String code;
    private final String description;

    ScannerConnectionType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return description;
    }

    public static ScannerConnectionType fromCode(String code) {
        if (code == null) {
            throw new IllegalArgumentException("Code cannot be null");
        }
        for (ScannerConnectionType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown code: " + code);
    }

    public static ScannerConnectionType fromDescription(String description) {
        if (description == null) {
            throw new IllegalArgumentException("Description cannot be null");
        }
        for (ScannerConnectionType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown description: " + description);
    }
}